package com.kgc.config;

import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FeignMultipartConfig {

    @Autowired
    private ObjectFactory<HttpMessageConverters> messageConverters;

    @Bean
    public Encoder feignEncoder() {
        // 创建 SpringEncoder 用于 JSON 编码
        SpringEncoder springEncoder = new SpringEncoder(messageConverters);
        // 包装 SpringFormEncoder，支持 multipart/form-data
        return new SpringFormEncoder(springEncoder);
    }
}
